package com.p2p.front.util;

/**
 * @author hongbo
 */
import java.util.Calendar;
import java.util.Random;

import org.apache.commons.lang.StringUtils;

import com.p2p.base.util.Encrypter;
import com.p2p.base.util.MD5Util;

public class MobileUtils {
	
	public static String createIdentifyingCode() {
		int[] array = {0,1,2,3,4,5,6,7,8,9};
		Random rand = new Random();
		for (int i = 10; i > 1; i--) {
			int index = rand.nextInt(i);
			int tmp = array[index];
			array[index] = array[i - 1];
			array[i - 1] = tmp;
		}
		int result = 0;
		for(int i = 0; i < 6; i++)
			result = result * 10 + array[i];

		return String.valueOf(result);
	}
	
	public static String createEmailUrl(Long emailId,String code,String baseUrl, int type, String userId) {
		StringBuilder url = new StringBuilder();
		url.append(baseUrl);
		url.append(Encrypter.encrypt(emailId.toString()));
		url.append("/");
		url.append(Encrypter.encrypt(code));
		url.append("/");
		url.append(MD5Util.md5(String.valueOf(Calendar.getInstance().getTimeInMillis())));
		url.append("/");
		url.append(Encrypter.encrypt(String.valueOf(type)));
		if(!StringUtils.isEmpty(userId)){
			url.append("/");
			url.append(Encrypter.encrypt(userId));
		}
		url.append(".html");
		return url.toString();
	}
}
